#include<bits/stdc++.h>
using namespace std;
//rp++
int n;
int a[100009];
bool f[100009];
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        memset(f,0,sizeof f);

        scanf("%d",&n);
        if(n > 30){
            return 0;
        }

        for(int i = 0; i < n; i++){
            scanf("%d",a+i);
        }
        long long ans = 0;
        for(int i = 0; i < (1<<n); i++){
            long long cur = 0;
            for(int j = 0; j < n; j++)
                f[j] = (i>>j) & 1;
            for(int j = 0; j < n; j++){
                for(int k = j-1; k >= 0; k--){
                    if(f[j] == f[k]){

                        if(a[j] == a[k]){
                            cur += a[j];
                        }
                        break;
                    }
                }
            }

            ans = max(ans,cur);
        }
        printf("%d\n",ans);

    }
    return 0;
}


//rp++
